#include "travel.h"


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern FILE* yyin;
extern int yylineno;
extern int failed;
extern Node* root;

int main(int argc, char *argv[]) {

    char outp[64] = {0};
    strcpy(outp, "sample/translate/ir/");
    
    if (argc < 2) return 1;
    
    FILE *f = fopen(argv[1], "r");
    if (!f) {
        perror(argv[1]);
        return 1;
    }
    yyrestart(f);
    yylineno = 1;
    yyparse();

    if (!failed) {
        // printTree(root, 0);
        FILE* out;
        if (argc == 2) {
            strcat(outp, "out.il");
        } else {
            strcat(outp, argv[2]);
        }
        semanticAnalysis(root, outp);
    }
    return 0;
}

void yyerror(const char *msg, int lineno) {
    printf("Error type B at Line %d: %s\n", yylineno, msg);
} 